package com.dykj.fireFighting.web.base.system.controller;

import java.util.*;

import com.dykj.fireFighting.api.base.system.entity.IpPort;
import com.dykj.fireFighting.api.base.system.service.IIpPortService;
import com.dykj.fireFighting.common.core.annotation.AutoLog;
import com.dykj.fireFighting.common.core.api.CommonResult;
import com.dykj.fireFighting.common.core.dto.CommonDto;
import com.dykj.fireFighting.common.core.vo.PageVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

import javax.validation.Valid;



/**
 * 接口
 *
 * @Author JacksonTu
 * @Date  2021-10-09 09:49:52
 */
@Slf4j
@Api(value = "接口", tags = {"接口"})
@RestController
@RequestMapping("sms/ipPort")
public class IpPortController {

    @DubboReference
    private IIpPortService ipPortService;


    /**
     * 列表
     *
     * @return
     */
    @AutoLog(value = "-分页列表查询")
    @ApiOperation(value = "分页列表", notes = "分页列表")
    @GetMapping("/list")
    @RequiresPermissions("sms/ipPort/list")
    public CommonResult<PageVo<IpPort>> treeGrid(CommonDto commonDto) {
        PageVo<IpPort> page = ipPortService.pageList(commonDto);
        return CommonResult.success(page);
    }

    /**
     * 获取信息
     */
    @AutoLog(value = "-获取信息")
    @ApiOperation(value = "获取信息", notes = "获取信息")
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", dataType = "String", required = true)
    @GetMapping("/info/{id}")
    @RequiresPermissions("sms/ipPort/info")
    public CommonResult<IpPort> info(@PathVariable("id") String id){
        IpPort ipPort = ipPortService.getById(id);
        return CommonResult.success(ipPort);
    }

    /**
     * 保存信息
     */
    @AutoLog(value = "-保存信息")
    @ApiOperation(value = "保存信息", notes = "保存信息")
    @PostMapping("/save")
    @RequiresPermissions("sms/ipPort/save")
    public CommonResult save(@Valid @RequestBody IpPort ipPort) {
        try {
                ipPortService.save(ipPort);
            return CommonResult.success("添加成功");
        } catch (Exception e) {
            log.error(e.getMessage());
            return CommonResult.failed("添加失败，请联系管理员");
        }
    }

    /**
     * 修改信息
     */
    @AutoLog(value = "-修改信息")
    @ApiOperation(value = "修改信息", notes = "修改信息")
    @PostMapping("/update")
    @RequiresPermissions("sms/ipPort/update")
    public CommonResult update(@Valid @RequestBody IpPort ipPort) {
        try {
                ipPortService.updateById(ipPort);
            return CommonResult.success("修改成功");
        } catch (Exception e) {
            log.error(e.getMessage());
            return CommonResult.failed("添加失败，请联系管理员");
        }
    }

    /**
     * 删除信息
     */
    @AutoLog(value = "-删除信息")
    @ApiOperation(value = "删除信息", notes = "删除信息")
    @ApiImplicitParam(paramType = "query", name = "ids", value = "ID数组", dataType = "String", required = true, allowMultiple = true)
    @PostMapping("/delete")
    @RequiresPermissions("sms/ipPort/delete")
    public CommonResult delete(@RequestBody String[]ids) {
        try {
                ipPortService.removeByIds(Arrays.asList(ids));
            return CommonResult.success("删除成功");
        } catch (Exception e) {
            log.error(e.getMessage());
            return CommonResult.failed("添加失败，请联系管理员");
        }
    }
}
